<template>
  <div>
    <breadcrumb class="breadcrumb-container"></breadcrumb>
    <el-row>
      <el-form>
        <el-form-item>
          <label for="">特约商户</label>
          <el-select filterable>
            <el-option></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <label for="">直属代理商</label>
          <el-select filterable>
            <el-option></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <label for="">月份</label>
          <el-date-picker type="month" placeholder="选择月"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <label for="">支付通道</label>
          <el-select>
            <el-option></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-button type="text" size="small" class="btn30 btn-search" icon="el-icon-search">查询</el-button>
      <el-button type="primary" size="small" icon="el-icon-download" class="btn30" @click="handleDownload">下载数据</el-button>
    </el-row>
    <el-row>
      <el-table :data="total_data" size="small">
        <el-table-column label="商户号" prop="id" align="center"></el-table-column>
        <el-table-column label="特约商户" prop="shop_name" align="center"></el-table-column>
        <el-table-column label="有效交易金额（元）" prop="money" align="center"></el-table-column>
        <el-table-column label="分润金额（元）" prop="run_money" align="center"></el-table-column>
        <el-table-column label="直属代理商" prop="agents" align="center"></el-table-column>
        <el-table-column label="月份" prop="month" align="center"></el-table-column>
      </el-table>
      <el-pagination :total="40" layout="total, prev, pager, next, jumper"  class="fr mt20"></el-pagination>
    </el-row>
  </div>
</template>

<script>
import Breadcrumb from '@/components/Breadcrumb'
export default {
  name: 'run',
  components: {
    Breadcrumb
  },
  data() {
    return {
      dialog: false,
      total_data: [
        {
          id: '2313',
          shop_name: '546',
          money: '646.5',
          run_money: '123120',
          agents: '165',
          month: '633'
        }
      ],
      dialog_data: [
        {
          pay: '支付宝',
          money: '331316',
          num: '164'
        }
      ]
    }
  },
  methods: {
    show(id) {
      this.dialog = true
    },
    handleDownload() {
      require.ensure([], () => {
        const { export_json_to_excel } = require('@/vendor/Export2Excel')
        const tHeader = ['商户号', '特约商户', '有效交易金额（元）', '分润金额（元）', '直属代理商', '月份'] // excel 表格头
        const filterVal = ['id', 'shop_name', 'money', 'run_money', 'agents', 'month'] // excel key值
        const list = this.total_data // 数据  Array
        const data = this.formatJson(filterVal, list) // 自行洗数据 按序排序的一个array数组
        export_json_to_excel(tHeader, data, '订单数据')
      })
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    }
  }
}
</script>

<style lang="scss" scoped>
.el-row{
  margin-top: 20px;
  .el-form{
    display: inline-block;
    vertical-align: top;
    .el-form-item{
      display: inline-block;
      vertical-align: middle;
      margin: 0;
      margin-left: 10px;
    }
  }
  .btn30{
    padding: 0;
    text-align: center;
    vertical-align: top;
    margin-top: 3px;
  }
  /deep/ .el-dialog{
    .el-dialog__header{
      border-bottom: 1px solid #ddd;
    }
    .el-dialog__body{
      padding: 10px 20px;
      font-size: 12px;
      ul{
        margin: 0;
        padding: 0;
        li{
          display: inline-block;
          width: 45%;
        }
      }
    }
  }
}
</style>
